package com.iflytek.cloud.thirdparty; import android.content.Context; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; public class ax { private static ax a; private aF b; private au c = null; private Context d; private ay e; private aC f; private av g = new aA(this); private ax(Context context) { this.b = new aF(context); this.d = context; this.f = new aC(context); this.e = new ay(this.b); aE.a(this.d, "load settings: pkgRun=" + this.e.g() + " periodRun=" + this.e.a() + " periodUpdate=" + this.e.b()); } public static synchronized ax a(Context context) { ax axVar; synchronized (ax.class) { if (a == null) { a = new ax(context); } axVar = a; } return axVar; } /* access modifiers changed from: private */ public void a(String str, int i) { if (i != 0 || str == null) { aE.a(this.d, "get config error:" + i); } else { this.e.c(System.currentTimeMillis()); aE.a(this.d, "get config success"); aE.a(this.d, str); b(str); aw.a(this.d); } this.c = null; } private void b(String str) { if (str == null || str.length() <= 0) { aE.a("LaunchSettings", "loadJson empty."); return; } String str2 = ""; try { JSONObject jSONObject = new JSONObject(new JSONTokener(str)); long j = jSONObject.getLong("updateperiod"); JSONObject jSONObject2 = jSONObject.getJSONObject("launch"); JSONArray jSONArray = jSONObject2.getJSONArray("runpackage"); String[] strArr = new String[jSONArray.length()]; for (int i = 0; i < jSONArray.length(); i++) { strArr[i] = jSONArray.getString(i); str2 = str2 + strArr[i] + ";"; } long j2 = jSONObject2.getLong("runperiod"); this.e.a(strArr); this.e.a(j); this.e.b(j2); aE.a(this.d, "parse json updateperiod:" + j + " runperiod:" + j2 + " runpackage:" + str2); } catch (JSONException e2) { aE.a(this.d, "parse json error:" + e2.getMessage()); } } private String d() { String f2 = f(); String e2 = e(); return "?t=" + f2 + "&p=" + e2; } private String e() { String a2 = this.f.a(); String b2 = this.f.b(); String f2 = this.e.f(); StringBuilder sb = new StringBuilder(); sb.append("imei="); if (a2 == null || a2.length() == 0) { a2 = "null"; } sb.append(a2); sb.append(",ua="); sb.append(b2); sb.append(",appid="); sb.append((f2 == null || f2.length() == 0) ? "null" : f2); sb.append(",sdkver=2.0"); sb.append(",pkg=" + this.d.getPackageName()); String sb2 = sb.toString(); char[] charArray = aD.a(sb2.getBytes()).toCharArray(); for (int i = 0; i < 8; i++) { char c2 = charArray[i]; charArray[i] = charArray[(charArray.length - 8) + i]; charArray[(charArray.length - 8) + i] = c2; } StringBuilder sb3 = new StringBuilder(); for (char c3 : charArray) { sb3.append(c3); } aE.a(this.d, sb2); return sb3.toString(); } private String f() { return new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date()); } public void a() { if (this.e.d() > System.currentTimeMillis()) { this.e.c(System.currentTimeMillis() - this.e.b()); } long currentTimeMillis = System.currentTimeMillis() - this.e.d(); long b2 = this.e.b(); if (currentTimeMillis <= b2) { aE.a(this.d, "check update interval=" + currentTimeMillis + " period=" + b2 + " ret=false"); } else if (this.c == null) { String str = "http://hxqd.openspeech.cn/launchconfig" + d(); this.c = new au(str, this.g); this.c.start(); aE.a(this.d, "check update start get config "); aE.a(this.d, str); } else { aE.a("LaunchSettings", "mGetThread running."); } } public void a(long j) { this.e.d(j); } public void a(String str, String str2) { if ("appid".equals(str)) { this.e.a(str2); } else { aE.a("LaunchSettings", "unkown key =" + str); } } public boolean a(String str) { if (this.e.c() == null || str == null) { return false; } for (String str2 : this.e.c()) { if (str.equals(str2)) { return true; } } return false; } public boolean b() { if (this.e.e() > System.currentTimeMillis()) { this.e.d(System.currentTimeMillis() - this.e.a()); } boolean z = false; long currentTimeMillis = System.currentTimeMillis() - this.e.e(); if (this.e.a() > 0 && currentTimeMillis > this.e.a()) { z = true; } aE.a(this.d, "check launch interval=" + currentTimeMillis + " period=" + this.e.a() + " ret=" + z); return z; } public long c() { return this.e.a(); } }